package service

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"wechat-moments_0926/pkg"
)

func FileUpload(c *gin.Context) {
	// 单文件
	file, _ := c.FormFile("file")
	log.Println(file.Filename)

	//url
	url := "./files/" + file.Filename

	// 上传文件至指定的完整文件路径
	c.SaveUploadedFile(file, url)

	fmt.Sprintf("'%s' uploaded!", file.Filename)

	upload := pkg.Upload(url)

	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "图片上传成功",
		"data":    upload,
	})
}
